package com.jing.ads.util;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.jing.ads.services.QueueService;

/**
 * 设置Alarm事件用于定时查询推送消息
 * @author zhangjingbd
 *
 */
public class AlarmUtils {
	
	private static final long INTERVAL_TIME = 30 * 60 * 1000;
	
	public static void launchAlarmForQueue(Context context, boolean isStart) {
		AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);  
        Intent intent = new Intent(context, QueueService.class);  
        PendingIntent pendingIntent = PendingIntent.getService(context, 1000, intent, 0);  
        long firstWake = System.currentTimeMillis() + INTERVAL_TIME;  
        if (isStart) {
        	am.setRepeating(AlarmManager.RTC, firstWake, INTERVAL_TIME, pendingIntent); 
		}else {
			am.cancel(pendingIntent);
		}
	}
}
